package com.gy.bearhelps.home.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gy.bearhelps.R;
import com.gy.bearhelps.news.bean.NewsItemBean;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by 高岳 on 2016/11/3.
 * Describe:主页广告
 */
public class HomeAdapter extends BaseAdapter {

    private Context context;
    private List<NewsItemBean> lists;

    public HomeAdapter(Context context, List<NewsItemBean> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(context, R.layout.adapter_news_item, null);
            holder = new ViewHolder();
            holder.imgTop = (ImageView) view.findViewById(R.id.adapter_news_item_img_top);
            holder.imgIcon = (ImageView) view.findViewById(R.id.adapter_news_item_img_icon);
            holder.tvName = (TextView) view.findViewById(R.id.adapter_news_item_tv_name);
            holder.tvTime = (TextView) view.findViewById(R.id.adapter_news_item_tv_time);
            holder.llContent = (LinearLayout) view.findViewById(R.id.adapter_news_item_ll_content);
            holder.line = view.findViewById(R.id.adapter_news_item_line);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.imgTop.setVisibility(View.GONE);
        holder.llContent.setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(lists.get(position).indexImg)) {
            holder.imgIcon.setVisibility(View.GONE);
        } else {
            holder.imgIcon.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(lists.get(position).indexImg,holder.imgIcon);
        }
        holder.tvName.setText(lists.get(position).title);
        holder.tvTime.setText(lists.get(position).releaseDate+"");
        return view;
    }

    class ViewHolder {
        ImageView imgTop, imgIcon;
        TextView tvName, tvTime;
        LinearLayout llContent;
        View line;
    }

}
